package com.fzh.client;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class client {

    public client()  {
        try {
            Socket socket=new Socket("localhost",9999);

            new ClientReadThread(socket).start();

            OutputStream os = socket.getOutputStream();

            DataOutputStream dos = new DataOutputStream(os);

            Scanner sc = new Scanner(System.in);
            while(true){
                System.out.println("请输入:");
                String msg=sc.nextLine();
                if("exit".equals(msg)) {
                    System.out.println("用户下线");
                    dos.close();
                    socket.close();
                    break;
                }
                dos.writeUTF(msg);
                dos.flush();
            }
        } catch (IOException e) {
            System.out.println("can’t connect to the server");
        }

    }
}
